<?php

namespace App\Listeners\V1;

use App\Constants\CreditConstant;
use App\Constants\InviteConstant;
use App\Events\AppEvent;
use App\Helpers\Logger\SLogger;
use App\Helpers\Utils;
use App\Models\Chain\Invite\DoInviteHandler;
use App\Models\Factory\InviteFactory;
use App\Models\Factory\UserInviteCodeFactory;
use App\Models\Orm\User_invite;
use App\Models\Orm\User_invite_code;
use App\Listeners\AppListener;
use DB;


class UserRegCreditListener extends AppListener
{


    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  AppEvent $event
     * @return void
     */
    public function handle(AppEvent $data)
    {
        $data = $data->data;
        if (isset($data['inviteCode'])) {

            //根据注册码,判断是否是有效的邀请码
            $result = Utils::isInviteCode($data['inviteCode']);
            if ($result) {
                #调用邀请责任链
                $inviteObj = new DoInviteHandler($data);
                $result =    $inviteObj->handleRequest();

               SLogger::getStream()->error($result['error']);

            }



            return false;




        }
        return false;

    }
}
